package cn.xy.base.server.config;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.List;

@Data
@Component
@ConfigurationProperties("openapi")
public class OpenApiConfig implements Serializable {

    public static String PERMISSION_ENTRY = "entry";
    private List<ThirdPart> thirdPartList;


    public ThirdPart getThirdPart(String token, String permission) {
        return thirdPartList.stream().filter(t -> t.getToken().equals(token) && t.getPermission().contains(permission)).findFirst().orElse(null);
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ThirdPart implements Serializable {
        private String token;
        private String secret;
        private List<String> permission;
    }
}
